package leetcode.每日一题;

import org.junit.Test;

/**
 * @author ：zsy
 * @date ：Created 2022/11/20 12:34 PM
 * @description：
 */
public class 香槟塔 {
    @Test
    public void test() {

    }

    class Solution {
        public double champagneTower(int poured, int query_row, int query_glass) {
            double[] row = {poured};
            for (int i = 1; i <= query_row; i++) {
                double[] nextRow = new double[i + 1];
                for (int j = 0; j < i; j++) {
                    double volume = row[j];
                    if (volume > 1) {
                        nextRow[j] += (volume - 1) / 2;
                        nextRow[j + 1] += (volume - 1) / 2;
                    }
                }
                row = nextRow;
            }
            return Math.min(1, row[query_glass]);
        }
    }
}
